import React from 'react';
import { connect } from 'dva';
import { Redirect } from 'umi';
import { PageLoading } from '@/components/PageLoading';
import { axhelper } from '@/shared/axhelper';

class SecurityLayout extends React.Component {
  state = {
    isReady: false,
  };

  componentDidMount() {
    return;
    if (axhelper.getToken() === true) {
      this.setState({
        isReady: true,
      });
      const { dispatch } = this.props;

      if (dispatch) {
        dispatch({
          type: 'user/fetchCurrent',
        });
      }
    } else {
      axhelper.login();
    }
  }

  render() {
    const { isReady } = this.state;
    const { children, loading, currentUser } = this.props;

    // if (!currentUser.userName || !isReady) {
    //   return <PageLoading />;
    // }

    // if (!currentUser.userid) {
    //   // return <Redirect to="/user/login"></Redirect>;
    // }

    return children;
  }
}

export default connect(({ user, loading }) => ({
  currentUser: user.currentUser,
  loading: loading.models.user,
}))(SecurityLayout);
